import * as React from "react";
import * as ReactDOM from "react-dom";
import { Router, Route } from 'react-router';
import { RouterStore } from "mobx-react-router";
import { useStrict } from 'mobx';
import { Provider } from 'mobx-react';
import * as store from './store';
import { Utils } from './util';
import { createHashHistory,createBrowserHistory  } from 'history';
import App from './components/App'

useStrict(true) // 不允许在动作之外进行状态修改

//增加索引签名
interface StringMap<T> {
	[x: string]: T;
}

const newStore: StringMap<any> = store;

const routerStore = new RouterStore();

const history = process.env.NODE_ENV === 'development' ? createHashHistory() : createBrowserHistory({ basename:'auth' });

let rootStore: StringMap<any> = {
	routerStore,
};

for (let s in newStore) {
	let n = new Utils.FirstStr();
	rootStore[n.FirstToLowerCase(s)] = new newStore[s]();
	
}

const route = (
	<Provider {...rootStore}>
		<Router history={history}>
			<Route path="/" component={App}>
			</Route>
		</Router>
	</Provider>
)

const renderApp = (TheApp: any) =>
	ReactDOM.render(
		route,
		document.getElementById("root")
	);
renderApp(route);